package shaka.groovy.db

import shaka.db.DbEngine

public class DbGryTools {
	static Object withNoTransaction(Closure c){
		DbEngine db = DbEngine.instance
		try{
			db.createTransaction()
			return c()
		}finally{
			db.close()
		}
	}

	static Object withTransaction(Closure c){
		DbEngine db = DbEngine.instance
		try{
			db.createTransaction()
			Object result = c()
			db.commit()
			return result
		}catch(e){
			db.rollback()
			throw e
		}finally{
			db.close()
		}
	}
}
